package exception;

public class TryCatchDemo{
    public static void main(String[] args) {
        System.out.println("程序开始了");
        try {
            String str = null;
            System.out.println(str.length());
            String str1 = "";
            System.out.println(str1.charAt(0));
            System.out.println("!!!!!!!!");//try语句块中如果某句代码出现了异常，那么其后的所有代码均不执行！！！
        }
        /*catch (NullPointerException e){
            System.out.println("出现了空指针，并解决了");
        }catch (StringIndexOutOfBoundsException e){
            System.out.println("出现了字符串下标越界，并解决了");
        }*/
        catch (NullPointerException | StringIndexOutOfBoundsException e){
            System.out.println("出现了空指针或字符串下标越界并解决了");
        }catch (Exception e){//这类异常的超类
            System.out.println("通用解决办法");
        }
        System.out.println("程序结束了");
    }
}